from django.db import models
from rbac import models as rbac_models
# Create your models here.

class ConnService(models.Model):
    sername = models.CharField(verbose_name="应用名",max_length=64)
    gitaddr = models.CharField(verbose_name="git地址",max_length=128)
    git_releases = models.CharField(verbose_name="git分支",max_length=256,default="master")

    def __str__(self):
        return self.sername

class Configuration(models.Model):
    sername = models.ForeignKey(verbose_name="对应服务",to="ConnService")

    node_num = models.IntegerField(verbose_name="部署节点数量",default=1)

    env_type_choices = ((1, "dev"), (2, "qa"), (3, "online"))
    env_type = models.SmallIntegerField(verbose_name="环境",choices=env_type_choices,default=1)

    group = models.ForeignKey(verbose_name="所属组",to="Group",blank=True,null=True)
    app_type_choices = ((1,"tomcat"),(2,"jar"))
    app_type = models.SmallIntegerField(verbose_name="应用类型",choices=app_type_choices,default=1)

    optimize_type_choices = ((1,"默认"),(2,"自定义"))
    optimize_type = models.SmallIntegerField(verbose_name="调优参数",choices=optimize_type_choices,default=1)
    optimize_detail = models.CharField(verbose_name="自定义调优参数",max_length=1024,blank=True,null=True)

    java_version_choices = ((18,1.8),(17,1.7))
    java_version = models.SmallIntegerField(verbose_name="java版本",choices=java_version_choices,default=2)

    system_type_choices = ((1,"centos6"),(2,"centos7"))
    system_release = models.SmallIntegerField(verbose_name="操作系统类型",choices=system_type_choices,default=1)

    configcenter_type_choices = ((1,"disconf"),(2,"apollo"))
    configcenter_type = models.SmallIntegerField(verbose_name="配置中心类型",choices=configcenter_type_choices,default=1)

    configcenter_addr = models.CharField(verbose_name="配置中心地址",max_length=128)

    jenkens_status_choices = ((1,"删除"),(2,"失败"),(3,"创建"))
    jenkens_status = models.SmallIntegerField(verbose_name="jenkins状态",choices=jenkens_status_choices,default=3)

    interface_type = models.CharField(verbose_name="接口类型",max_length=64,blank=True,null=True)
    cpu_capacity_choices = ((1,1),(2,0.8),(3,0.4))
    cpu = models.SmallIntegerField(verbose_name="CPU capacity",choices=cpu_capacity_choices,default=1)
    mem_capacity_choices = ((2,2),(1,1))
    mem = models.SmallIntegerField(verbose_name="mem capacity",choices=mem_capacity_choices,default=1)

    port = models.IntegerField(verbose_name="应用使用端口",blank=True,null=True)
    request_path = models.CharField(verbose_name="服务请求路径",max_length=64,default="/")
    service_path = models.CharField(verbose_name="服务访问路径",max_length=64,default="/")
    hostname = models.CharField(verbose_name="域名",max_length=128,blank=True,null=True)

    ingress_type_choices = ((1,"已创建"),(2,"创建失败"),(3,"创建"))
    ingress_type = models.SmallIntegerField(verbose_name="INGRESS状态",choices=ingress_type_choices,default=3)

    related_user = models.ForeignKey(verbose_name="创建该app的用户",to=rbac_models.User,blank=True,null=True)

    personalize_type_choices = ((1,"设置"),(2,"不设置"))
    personalize = models.SmallIntegerField(verbose_name="个性化设置",choices=personalize_type_choices,default=2)
    persontext = models.CharField(verbose_name="个性化参数",max_length=256,blank=True,null=True)

    createDate = models.DateField(blank=True,auto_now_add=True)
    updateDate = models.DateField(blank=True,auto_now=True)

    def __str__(self):
        return self.sername.sername + "-" + self.group.name

class Group(models.Model):
    name = models.CharField(verbose_name="组名称",max_length=32,blank=True,null=True)

    def __str__(self):
        return self.name